package com.xmad.ksadutils.AdSDK;

import android.app.Activity;
import android.content.Context;

import androidx.fragment.app.Fragment;


import com.kwad.sdk.api.KsAdSDK;
import com.kwad.sdk.api.SdkConfig;
import com.xmad.ksadutils.AdSDK.AdBase.AdBaseLoad;
import com.xmad.ksadutils.AdSDK.AdBase.AdBuilder;
import com.xmad.ksadutils.AdSDK.AdBase.Manufactor;
import com.xmad.ksadutils.AdSDK.AdBase.TTAdManagerHolder;
import com.xmad.ksadutils.AdSDK.AdMold.Pangolin.PGloadRewardVideoAd;
import com.xmad.ksadutils.AdSDK.Utlis.SpUtils;
import com.xmad.ksadutils.R;

/**
 * @Author: 郝家伟
 * @CreateDate: 2021/8/18
 */
public class AdUtil {
    private volatile static AdUtil mInstance;
    public AdBaseLoad baseLoad;
    Activity context;
    public static boolean ToastCode;

    /**
     * 单例模式
     *
     * @return
     */
    public static AdUtil getInstance() {
        if (mInstance == null) {
            synchronized (AdUtil.class) {
                if (mInstance == null) {
                    mInstance = new AdUtil();
                }
            }
        }
        return mInstance;
    }
    public AdUtil get(Activity context){
        this.context=context;
        return this;
    }

    public AdUtil get(Fragment fragment){
        this.context=fragment.getActivity();
        return this;
    }


    public AdUtil setToastCode(boolean ToastCode) {
        this.ToastCode=ToastCode;
        return this;
    }


    public AdUtil setAdLoad(AdBaseLoad baseLoad) {
        this.baseLoad = baseLoad;
        return this;
    }


    public static void init(Context context, Manufactor manufactor){
        if (manufactor.getKwai()!=null&&!manufactor.getKwai().equals("")){
            initKSSDK(context,manufactor.getKwai());
        }
        if (manufactor.getPangolin()!=null&&!manufactor.getPangolin().equals("")){
            initPGSDK(context,manufactor.getPangolin());
        }
        SpUtils.getInstance().init(context);
    }

    public static void initPGSDK(Context context, String appId) {
        TTAdManagerHolder.init(context,appId);
    }

    public static void initKSSDK(Context context, String appId) {
        KsAdSDK.init(context, new SdkConfig.Builder()
                .appId(appId) // 测试aapId，请联系快手平台申请正式AppId，必填
                .appName((context.getString(R.string.app_name))) // 测试appName，请填写您应用的名称，非必填
                .nightThemeStyleAssetsFileName("ks_adsdk_night_styles.xml")
                .showNotification(true) // 是否展示下载通知栏
                .debug(true)
                .build());
    }

    public AdUtil load(){
         setAdLoad(new AdBuilder(PGloadRewardVideoAd.getInstance()).show());
         return this;
    }

    public Activity getContext() {
        return context;
    }


     // 全局ToastCode
      //AdUtil.getInstance().setToastCode(true);
}
